#!/usr/bin/env python
# coding:utf-8

import MySQLdb, sys

reload(sys)
sys.setdefaultencoding('utf8')

# sql=sys.argv[1]

def select_mysql(sql):
    conn = MySQLdb.connect(host='10.0.0.142', user='daxmall_r', passwd='2hGUnCKoEuvkWNgRbvwo', db='daxmall',
                           charset='UTF8')

    cur = conn.cursor()
    reCount = cur.execute(sql)

    nRet = cur.fetchall()
    cur.close()

    conn.close()
    return nRet


def insert_mysql(sql):
    conn = MySQLdb.connect(host='121.201.68.21', port=3307, user='jiang', passwd='jiangwenhui', db='daxiangzhanshi',

                           charset='UTF8')

    cur = conn.cursor()

    cur.execute(sql)
    nRet = cur.fetchall()
    conn.commit()

    cur.close()

    conn.close()
    return nRet

if __name__ == "__main__":
    sql="SELECT SUM(s.total) AS 订单总金额  FROM ls_sub s  WHERE s.update_date >= curdate() AND s. STATUS > 1 AND s. STATUS !=5 "
    data =select_mysql(sql)[0][0]
    update_sql="update zhifu_total set zhifu_total=%s"%data
    insert_mysql(update_sql)
